﻿//Author:Christian TQ
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace TQ.Sharepoint.Webparts.ListQuickSearch
{

    public class ListQuickSearch : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/TQ.Sharepoint.Webparts/ListQuickSearch/ListQuickSearchUserControl.ascx";

        private string _fieldName = null;
        private string _listName = null;
        private int _numItems = 0;


        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [Category("Configurations")]
        [WebDisplayName("List/Library Name")]
        [Description("Set the document list/library name")]
        public string listName
        {
            get
            {
                if (_listName == null)
                    _listName = "Document Library";//default name
                return _listName;
            }
            set
            { _listName = value; }
        }


        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [Category("Configurations")]
        [WebDisplayName("Field Name")]
        [Description("Set the field name to search on")]
        public string fieldName
        {
            get
            {
                if (_fieldName == null)
                    _fieldName = "BaseName";//default name for doc lib
                return _fieldName;
            }
            set
            { _fieldName = value; }
        }

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [Category("Configurations")]
        [WebDisplayName("Items per page")]
        [Description("Number of items per page result")]
        public int numItems
        {
            get
            {
                if (_numItems == 0)
                    _numItems = 20;//default number
                return _numItems;
            }
            set
            { _numItems = value; }
        }





        protected override void CreateChildControls()
        {

            ListQuickSearchUserControl control = (ListQuickSearchUserControl)Page.LoadControl(_ascxPath);
            control.listName = listName;
            control.numItems = numItems;
            control.fieldName = fieldName;
            Controls.Add(control);
        }
    }
}